﻿using System;
using System.Collections.Generic;
using System.Text;

namespace FiveStone.MyStack
{
    /// <summary>
    /// 棋子记录
    /// </summary>
    public class MyStack
    {        
        public const int MAXSIZE = 5000;
        public struct FSStack
        {
            public string[] data;
            public int top;
        }

        public FSStack st = new FSStack();

        public void CreatStack()
        {
            st.data = new string[MAXSIZE];
            st.top = -1;
        }

        public bool Insert(string str)
        {
            if (st.top == MAXSIZE - 1)
            {
                return false;
            }
            else
            {
                st.top++;
                st.data[st.top] = str;
                return true;
            }
        }

        public bool Delete()
        {
            if (st.top == -1)
            {
                return false;
            }
            else
            {
                st.top--;
                return true;
            }
        }

        public string GetTop()
        {
            return st.data[st.top].ToString();
        }

        /// <summary>
        /// 得到电脑本次下棋位置
        /// </summary>
        /// <returns></returns>
        public string GetPC()
        {
            if (st.top != -1)
            {
                return "PC:" + (st.data[st.top].ToString());
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 得到人本次下棋位置
        /// </summary>
        /// <returns></returns>
        public string GetPerson()
        {
            if (st.top != -1&&st.top>0)
            {
                return "我:" + (st.data[st.top-1].ToString());
            }
            else
            {
                return "";
            }
        }

        /// <summary>
        /// 得到本次下棋记录
        /// </summary>
        /// <returns></returns>
        public string GetGobangRecord(string PlayerName)
        {
            if (st.top != -1)
            {
                return String.Format("[{0}] {1}:{2}",st.top+1, PlayerName, (st.data[st.top].ToString()));
            }
            else
            {
                return "";
            }
        }
    }
}
